function SaveHtmlForm()
{
    var hiddenField = document.getElementById("SavedHtmlForm");
    if(hiddenField != null)
    {
        var theform;
        hiddenField.value = "";
        theform = document.getElementById("formContent");
        if(theform != null)
        {
            hiddenField.value = theform.innerHTML;
        }
    }
}

function getByName(name) {
	var elements = document.getElementsByName(name);
	if (elements.length > 0)
	{
		return elements[0];
	}
	return null;
}

function CheckMandatoryFields(list,listreg,path,lang,evt)
{
	var tabFields;
	var obj;
	var obj2;
	var obj3;
	var errorString = "";
	var errorString2 = "";
	var errorString3 = "";
	var errorString4 = "";
	var errorString5 = "";
	var logExist;
	var mailExist;
	var captchaOK;
	
	tabFields = list.split('|');
	for (i = 0; i < tabFields.length; i++)
	{
	    var obj = getByName(tabFields[i]);

		if(obj != undefined && obj != null)
		{
			switch(obj.type)
			{
				case "text":
				case "textarea":
				case "file":
				//case "select-one":
				case "select-multiple":
				    if(obj.value == undefined || obj.value == null || obj.value == "")
					{
						for(var j=0;j<=9;j++)
						{
							tabFields[i].replace("/_"+j.toString()+"/","");
							
						}
						errorString += " - " + tabFields[i] + "\n";
					}
					else
					{
					    var stringValue = obj.value;
					    reg = new RegExp(' ', "g");
	                    stringValue = stringValue.replace(reg,'');
	                    if(stringValue == "")
	                    {
	                        for(var j=0;j<=9;j++)
						    {
							    tabFields[i].replace("/_"+j.toString()+"/","");
    							
						    }
						    errorString += " - " + tabFields[i] + "\n";
	                    } 
					}
					break;
				case "select-one":
				    if(obj[0].selected)
				    {
				        for(var j=0;j<=9;j++)
						{
							tabFields[i].replace("/_"+j.toString()+"/","");
							
						}
						errorString += " - " + tabFields[i] + "\n";
				    }
				    break
					//alert(obj.type + " " + obj.value);
					
				/*case "checkbox":
					alert(obj.type + " " + obj.checked);
					if(obj.checked == "false")
					{
						errorString += tabFields[i] + " ";
					}
					break;*/
				default:
					//alert(tabFields[i] + " " + obj + obj.checked);
					break;
			}
		}
	}
	
	if(errorString != "")
	{
	    var requireErrorObj;
	    requireErrorObj = getByName('_requirefieldserrortext');
	    if(requireErrorObj != undefined && requireErrorObj != null)
        {
            errorString = requireErrorObj.value + "\n\n" /*+ errorString + "\n---------------------------------------------------\n\n"*/;
        }
        else
        {
		    errorString = GetErrorMessage("require",lang) + "\n\n" /*+ errorString + "\n---------------------------------------------------\n\n"*/;
		}
	}
	
	tabFields = listreg.split('$');
	for(i=0; i<tabFields.length; i++)
	{
		tabFields2 = tabFields[i].split('!');
		obj = getByName(tabFields2[0]);
		if(obj != undefined && obj != null)
		{
			if(obj.value != undefined)
			{
			//alert(tabFields2[1]);
				var myrxp = new RegExp("^" + tabFields2[1] + "$");
				if(!myrxp.test(obj.value.toString()))
				{
					errorString2 += tabFields2[0] + "\n";
				}
			}	
		}
	}
	
	if(errorString2 != "")
	{
        var regexErrorObj;
	    regexErrorObj = getByName('_regexfieldserrortext');
	    if(regexErrorObj != undefined && regexErrorObj != null)
        {
            errorString2 = regexErrorObj.value + "\n\n"/* + errorString2 + "\n---------------------------------------------------\n\n"*/;
        }
        else
        {
		    errorString2 = GetErrorMessage("regex",lang) + "\n\n"/* + errorString2 + "\n---------------------------------------------------\n\n"*/;
		}
	}
	
		logExist = "false";
	obj = getByName('_UserForm_UserLogin');
	if(obj != undefined && obj != null && !obj.readOnly)
	{
		logExist = LoginExists(obj.value,path);
		
		if(logExist != null && logExist == "true")
		{
			obj2 = getByName('_UserForm_ErrorLoginExist');
			if(obj2 != undefined && obj2 != null)
			{
				if(obj2.value != "")
				{
					errorString3 += obj2.value+"\n";
				}
				else
				{
					errorString3 += GetMemberErrorMessage("login",lang) + "\n";
				}
			}
			else
			{
				errorString3 += GetMemberErrorMessage("login",lang) + "\n";
			}
		}
	}
	
	mailExist = "false";
	obj = getByName('_UserForm_Email');
	var objmodif = getByName('_UserForm_UserModify');
	if(objmodif == undefined || objmodif == null)
	{
	    if(obj != undefined && obj != null && !obj.readOnly)
	    {
		    mailExist = EmailExists(obj.value,path);
    		
		    if(mailExist != null && mailExist == "true")
		    {
			    obj2 = getByName('_UserForm_ErrorEmailExist');
			    if(obj2 != undefined && obj2 != null)
			    {
				    if(obj2.value != "")
				    {
					    errorString3 += obj2.value+"\n";
				    }
				    else
				    {
					    errorString3 += GetMemberErrorMessage("email",lang) + "\n";
				    }
			    }
			    else
			    {
				    errorString3 += GetMemberErrorMessage("email",lang) + "\n";
			    }
		    }
	    }
	}
	
	obj = getByName('_UserForm_Password');
	if(obj != undefined && obj != null)
	{
	    //test strong password
	    var strongPassExp = new RegExp("(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,})$");
		if(!strongPassExp.test(obj.value.toString()))
		{
			errorString5 += GetMemberErrorMessage("strongpassword",lang) + "\n";
		}
	    
		obj2 = getByName('_UserForm_ConfirmPassword');
		if(obj2 != undefined && obj2 != null)
		{
			if(obj.value != obj2.value)
			{
				obj3 = getByName('_UserForm_ErrorConfirmPassword');
				if(obj3 != undefined && obj3 != null)
				{
				    if(obj3.value != "")
				    {
					    errorString3 += obj3.value+"\n";
					}
					else
				    {
					    errorString3 += GetMemberErrorMessage("password",lang) + "\n";
				    }
				}
				else
				{
					errorString3 += GetMemberErrorMessage("password",lang) + "\n";
				}
			}
		}
	}
	
	if(errorString3 != "")
	{
	    var memberErrorObj;
	    memberErrorObj = getByName('_memberfieldserrortext');
	    if(memberErrorObj != undefined && memberErrorObj != null)
        {
            errorString3 = memberErrorObj.value + "\n\n" + errorString3 + "\n" + errorString5 + "\n---------------------------------------------------\n\n";
        }
        else
        {
		    errorString3 = GetErrorMessage("member",lang) + "\n\n" + errorString3 + "\n" + errorString5 + "\n---------------------------------------------------\n\n";
		}
	}
	
	captchaOK = "false";
	obj = getByName('_UserForm_Captcha');
	if(obj != undefined && obj != null)
	{
		captchaOK = CheckCaptcha(obj.value,path);
		if(captchaOK == "false")
		{
		    var captchaErrorObj;
		    captchaErrorObj = getByName('_captchafieldserrortext');
		    if(captchaErrorObj != undefined && captchaErrorObj != null)
	        {
	            errorString4 += captchaErrorObj.value + "\n\n---------------------------------------------------\n\n";
	        }
	        else
	        {
			    errorString4 += GetErrorMessage("captcha",lang) + "\n\n---------------------------------------------------\n\n";
			}
		}
	}
	
	if(errorString != "" || errorString2 != "" || errorString3 != "" || errorString4 != "" || errorString5 != "")
	{
		alert(ReplaceString(errorString) + ReplaceString(errorString2) + ReplaceString(errorString3) + ReplaceString(errorString4) + ReplaceString(errorString5));
		//window.event.cancelBubble = true;
		if (window.event)
		{
            window.event.cancelBubble = true;
        }
        else
        {       
            evt.cancelBubble = true;
        }
		return false;
	}
	else
	{
		return true;
	}				
}

function ReplaceString(texte)
{
    var reg;
    var toReplace;
    
	for(var c=25;c>=0;c--)
	{
		toReplace = '_'+c;	
	    reg = new RegExp(toReplace, "gi");
	    texte = texte.replace(reg,'');
	}
	reg = new RegExp('_', "gi");
	texte = texte.replace(reg,'');
	return texte;
}

function createXMLHttpRequest() 
{
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
}

function GetResponse(response)
{
    var responseDocument;
	var parser;
	
    try
    {
	    responseDocument = new ActiveXObject("Microsoft.XMLDOM");
        responseDocument.async="false";
        responseDocument.loadXML(response);
        return responseDocument.documentElement.firstChild.text;
    }
    catch(e)
    {
        try
        {
            parser=new DOMParser();
            responseDocument=parser.parseFromString(response,"text/xml");
            return responseDocument.documentElement.firstChild.nodeValue;
        }
        catch(g)
        {
            return null;
        }
    }
}

function LoginExists(login,path)
{
	var xmlHttp;
	var url;
	var result = null;
	
	try
    {
		xmlHttp = createXMLHttpRequest();
		post = "login=" + login;
		url = location.protocol + "//" + location.hostname+path+"/Admin/WebServices/PageSvc.asmx";
		xmlHttp.open("POST", url + '/LoginExists', false);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(post);
	    	
		result = GetResponse(xmlHttp.responseText);
    }
    catch(e){alert('Login error : '+e.description);}
	   
	return result;
}

function EmailExists(email,path)
{
	var xmlHttp;
	var url;
	var result = null;
	
	try
    {
		xmlHttp = createXMLHttpRequest();
		post = "email=" + email;
		url = location.protocol + "//" + location.hostname+path+"/Admin/WebServices/PageSvc.asmx";
		xmlHttp.open("POST", url + '/EmailExists', false);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(post);
		
		result = GetResponse(xmlHttp.responseText);

    }
    catch(e){alert('Email error : '+e.description);}
	   
	return result;
}

function CheckCaptcha(text,path)
{
	var xmlHttp;
	var url;
	var result = null;
	
	try
    {
		xmlHttp = createXMLHttpRequest();
		post = "text=" + text;
		url = location.protocol + "//" + location.hostname+path+"/Admin/WebServices/PageSvc.asmx";
		xmlHttp.open("POST", url + '/CheckCaptcha', false);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(post);
	  
		result = GetResponse(xmlHttp.responseText);
    }
    catch(e){alert('Captcha error : '+e.description);}
	   
	return result;
}

/*LoginExists("admin");*/


function GetErrorMessage(type, lang)
{
    var message = "";
    switch(type)
    {
        case "require":
            switch(lang)
            {
                case "fr":
                message = "Veuillez remplir les champs obligatoires ";
                break;
                case "nl":
                message = "Vul de verplichte velden ";
                break;
                default:
                message = "Please fill-in all the mandatory fields ";
                break;
            }
            break;
        case "regex":
            switch(lang)
            {
                case "fr":
                message = "Veuillez v\351rifier le format des valeurs entr\351es ";
                break;
                case "nl":
                message = "Controleer het formaat van de input-waarden ";
                break;
                default:
                message = "Please check the format of the input values ";
                break;
            }
            break;
        case "member":
            switch(lang)
            {
                case "fr":
                message = "Veuillez v\351rifier les champs du formulaire d'inscription: ";
                break;
                case "nl":
                message = "Controleer de velden van het inschrijving formulier: ";
                break;
                default:
                message = "Please check the member registration fields: ";
                break;
            }
            break;
        case "captcha":
            switch(lang)
            {
                case "fr":
                message = "Veuillez v\351rifier le code visuel (captcha).";
                break;
                case "nl":
                message = "Controleer de visuele code (captcha).";
                break;
                default:
                message = "Please check the visual code (captcha).";
                break;
            }
            break;
    }
    
    return message;
}

function GetMemberErrorMessage(type,lang)
{
    var message = "";
    switch(type)
    {
        case "login":
            switch(lang)
            {
                case "fr":
                message = "Le login est d\351j\340 utilis\351.";
                break;
                case "nl":
                message = "De login is al in gebruik.";
                break;
                default:
                message = "Login already exists.";
                break;
            }
            break;
        case "password":
            switch(lang)
            {
                case "fr":
                message = "La confirmation du mot de passe doit \352tre identique.";
                break;
                case "nl":
                message = "De bevestiging van het wachtwoord moet identiek zijn.";
                break;
                default:
                message = "Confirm password must be identical.";
                break;
            }
            break;
        case "strongpassword":
            switch(lang)
            {
                case "fr":
                message = "Le mot de passe doit contenir au moins 8 caract\350res, contenant au moins un chiffre et un caract\350re alphab\351tique, et ne doit pas contenir de caract\350res sp\351ciaux.";
                break;
                case "nl":
                message = "Wachtwoord moet uit minstens 8 tekens, container ten minste een cijfer en een letter uit het alfabet, en mag geen speciale tekens bevatten.";
                break;
                default:
                message = "Password must contain at least 8 characters, contain at least one digit and one alphabetic character, and must not contain special characters.";
                break;
            }
            break;
        case "email":
            switch(lang)
            {
                case "fr":
                message = "L'adresse e-mail est d\351j\340 utilis\351e.";
                break;
                case "nl":
                message = "Het e-mailadres is al in gebruik.";
                break;
                default:
                message = "E-mail address already exists.";
                break;
            }
            break;
    }
    
    return message;
}


/* FAQ + Tabbed section */

function showhide(id)
{
	var obj;
	obj = document.getElementById(id);
	if (obj.style.display == 'none')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.display = 'none';
	}
}

function selectedTab(tab,tabContainer, id, begin, end, selected)
{
    var selectObj;
    var isSelected = false;
    var selectedTab;
    var img;
    
    /*******unselect all*******/
    var container = document.getElementById(tabContainer);
    if(container != null)
    {
    
        var displayStyle = null;
		displayStyle = container.getElementsByTagName("input");
		if(displayStyle != null)
		{
		    if(displayStyle[0] != null)
		    {
		        if(displayStyle[0].value == "selectedonly")
		        {
			        
                    var tabs = container.getElementsByTagName("li");
                    for(var i = 0; i < tabs.length; i++)
                    {
                        tabs[i].removeAttribute("id");
                        
                        tabs[i].setAttribute("class","SiteNOTE_Tab");
                        tabs[i].setAttribute("className","SiteNOTE_Tab");
                    }
                }
            }
        }
    }
    /*****************/
    
    selectObj = document.getElementById(selected);
    if(tab.id == "SiteNOTE_SelectedTab")
    {
        tab.removeAttribute("id");
        selectObj.name = undefined;
         selectObj.style.display = 'none';
    }
    else
    {
        tab.setAttribute("id","SiteNOTE_SelectedTab");
        selectObj.name = 'SiteNOTE_SelectedTab';
         selectObj.style.display = 'block';
    }
}

function hide(tab,id, begin, end)
{
    tab.setAttribute("className","SiteNOTE_TabHover");
    tab.setAttribute("class","SiteNOTE_TabHover");
    
	var obj;
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
			obj.style.display = 'none';
		}
	}
}

function firsthide(id, begin, end)
{
	var obj;
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
			obj.style.display = 'none';
		}
	}
}


function resetTab(tab, id, begin, end)
{
    tab.setAttribute("className","SiteNOTE_Tab");
    tab.setAttribute("class","SiteNOTE_Tab");
	var obj;
	
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
		    if(obj.name == undefined)
		    {
		        
			    obj.style.display = 'none';
			}
			else
		    {
		        if(obj.name == 'SiteNOTE_SelectedTab')
	            {
	                obj.style.display = 'block';
	            }
		    }
		}
	}
}

function ResizeAllTabContainer()
{

	var obj;
	var first = null;
	var displayStyle;
	for(var i = 0; i < 10; i++)
	{
		obj = document.getElementById('posContainer_' + i);
		if (obj != null)
		{
			if(first == null)
			{
				first = i;
			}
			
			//alert(document.getElementById("SectionTabContainer").offsetHeight);
//			if(document.getElementById("SectionTabContainer") != null)
//			{
//			    obj.style.height = getHigher('section_' + i + '_', 0,99) + document.getElementById("SectionTabContainer").offsetHeight +"px";
//			}
//			else
//			{
//			    obj.style.height = getHigher('section_' + i + '_', 0,99) +"px";
//			}
			firsthide('section_' + i + '_',0,10);
			//showhide('section_'+ i +'_1');
			displayStyle = null;
			displayStyle = obj.getElementsByTagName("input");
			if(displayStyle != null)
			{
			    if(displayStyle[0] != null)
			    {
			        if(displayStyle[0].value == "selectedonly")
			        {
			            selectFirst(obj, 'section_'+ i +'_1');
			        }
			    }
			}
		}
	}
	//showhide('section_'+first+'_1');
}

function selectFirst(container,tab)
{
    var selectObj;
    var img = null;
    
    if(container != null)
    {
        var tabs = container.getElementsByTagName("li");
        if(tabs != null)
        {
            if(tabs[0] != null)
            {
                img = tabs[0].getElementsByTagName('img');
                
                if(img != null)
                {
                    if(img[0] != null)
                    {
                        if(img[0].id == "SiteNOTE_ImgTabTag")
                        {
                            tabs[0].setAttribute("id","SiteNOTE_SelectedImageTab");
                        }
                        else
                        {
                            tabs[0].setAttribute("id","SiteNOTE_SelectedTab");
                        }
                    }
                    else
                    {
                        tabs[0].setAttribute("id","SiteNOTE_SelectedTab");
                    }
                }
                else
                {
                    tabs[0].setAttribute("id","SiteNOTE_SelectedTab");
                }
                selectObj = document.getElementById(tab);
                if(selectObj != null)
                {
                    if(img != null)
                    {
                        if(img[0] != null)
                        {
                            if(img[0].id == "SiteNOTE_ImgTabTag")
                            {
                                selectObj.name = 'SiteNOTE_SelectedImageTab';
                            }
                            else
                            {
                                selectObj.name = 'SiteNOTE_SelectedTab';
                            }
                        }
                        else
                        {
                            selectObj.name = 'SiteNOTE_SelectedTab';
                        }
                    }
                    else
                    {
                        selectObj.name = 'SiteNOTE_SelectedTab';
                    }
                    selectObj.style.display = 'block';
                }
            }
        }
    }
}

function getHigher(id, begin, end)
{
	var obj;
	var higher = 0;
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
		//alert(obj.offsetHeight);
			if(obj.offsetHeight  > higher)
			{
				higher = obj.offsetHeight ;
			}
		}
	}
	return higher;
}

/* IMAGE TAB */

function selectedImgTab(tab,tabContainer, id, begin, end, selected)
{
    var selectObj;
    var isSelected = false;
    var selectedTab;
    var hidden;
    var img;
    
    /*******unselect all*******/
    var container = document.getElementById(tabContainer);
    if(container != null)
    {
        var displayStyle = null;
		displayStyle = container.getElementsByTagName("input");
		if(displayStyle != null)
		{
		    if(displayStyle[0] != null)
		    {
		        if(displayStyle[0].value == "selectedonly")
		        {
		        
                    var tabs = container.getElementsByTagName("li");
                    for(var i = 0; i < tabs.length; i++)
                    {
                    
                        hidden = null;
                        img = null;
                        tabs[i].removeAttribute("id");
                        tabs[i].setAttribute("class","SiteNOTE_ImageTab");
                        tabs[i].setAttribute("className","SiteNOTE_ImageTab");
                        
                        hidden = tabs[i].getElementsByTagName('input');
                        if(hidden != null)
                        {
                            if(hidden[0] != null)
                            {
                                img = tabs[i].getElementsByTagName('img');
                                
                                if(img != null)
                                {
                                    if(img[0] != null)
                                    {
                                        img[0].setAttribute("src",hidden[0].value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /***********************/
    
    selectObj = document.getElementById(selected);
    if(tab.id == "SiteNOTE_SelectedImageTab")
    {
        tab.removeAttribute("id");
        selectObj.name = undefined;
         selectObj.style.display = 'none';
    }
    else
    {
        tab.setAttribute("id","SiteNOTE_SelectedImageTab");
        selectObj.name = 'SiteNOTE_SelectedImageTab';
         selectObj.style.display = 'block';
    }
}

function hideImg(tab,id, begin, end)
{
    tab.setAttribute("className","SiteNOTE_ImageTabHover");
    tab.setAttribute("class","SiteNOTE_ImageTabHover");
    
	var obj;
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
			obj.style.display = 'none';
		}
	}
}

function resetImgTab(tab, id, begin, end)
{
    tab.setAttribute("className","SiteNOTE_ImageTab");
    tab.setAttribute("class","SiteNOTE_ImageTab");
	var obj;
	
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
		    if(obj.name == undefined)
		    {
		        
			    obj.style.display = 'none';
			}
			else
		    {
		        if(obj.name == 'SiteNOTE_SelectedImageTab')
	            {
	                obj.style.display = 'block';
	            }
		    }
		}
	}
}

function setImgSource(tab, src1, src2)
{
    var img;
    img = tab.getElementsByTagName('img');
    if(img != null)
    {
        if(img[0] != null)
        {
            if(src2 != '')
            {
                if(tab.id == "SiteNOTE_SelectedImageTab")
                {
                
                    img[0].setAttribute("src",src2);
                }
                else
                {
                
                    img[0].setAttribute("src",src1);
                }
            }
            else
            {
                if(tab.id != "SiteNOTE_SelectedImageTab")
                {
                    
                    img[0].setAttribute("src",src1);
                }
            }
        }
    }
}

/* END IMAGE TAB */

/*function selectedTab(tab, id, begin, end, selected)
{
    var selectObj;
    var isSelected = false;
    var selectedTab;
    
    selectedTab = document.getElementById("SelectedTab");
    if(selectedTab != null)
    {
        selectedTab.removeAttribute("id");
    }
    
    if(selectedTab != tab)
    {
        tab.setAttribute("id","SelectedTab");
    }
    
    selectObj = document.getElementById(selected);
    if(selectObj != null)
	{
        if(selectObj.name == 'SelectedTab')
	    {
	        isSelected = true;
	    }
	}
    
    var obj;
	for(var i = begin; i < end; i++)
	{
		obj = document.getElementById(id + i);
		if (obj != null)
		{
		    if (obj.name != undefined)
		    {
		        obj.name = undefined;
			    obj.style.display = 'none';
			}
		}
	}
   
	if(selectObj != null)
	{
	    if(!isSelected)
	    {
            selectObj.name = 'SelectedTab';
	        selectObj.style.display = '';
	    }
	}
}*/


